from pathlib import Path
from hashlib import md5


file_path = Path(r'/Volumes/新加卷/pic')

idx = 0
null = 0
for folder in file_path.iterdir():
    if not folder.is_dir():
        print(folder)
        continue

    for file in folder.iterdir():
        if file.stem.startswith('.'):
            print('无效文件', file.name)
            file.unlink()
            continue

        idx += 1
        file_hash = md5(file.read_bytes()).hexdigest()
        if file_hash != file.stem:
            print(file_hash, file.as_posix())
            # file.unlink()

        # if not file.read_bytes():
        #     null += 1
        #     print(null, file.as_posix())


        if idx % 500 == 0:
            print(idx)
print(idx)